package com.leejxx.admin.controller.v1;

import com.leejxx.admin.service.AdChannelService;
import com.leejxx.model.admin.pojos.AdChannel;
import com.leejxx.model.admin.dtos.ChannelDto;
import com.leejxx.model.common.dto.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author LeeJx
 * @ClassName AdChannelController
 * @Description TODO
 * @date 2021/2/4 14:21
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/v1/channel")
@Slf4j
public class AdChannelController {

    @Autowired
    private AdChannelService adChannelService;

    @RequestMapping("/list")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto channelDto) {
        log.info("[data]:{}", channelDto);
        return adChannelService.findByNameAndPage(channelDto);
    }

    @RequestMapping("/save")
    public ResponseResult saveChannel(@RequestBody AdChannel adChannel) {
        log.info("[data]:{}", adChannel);
        return adChannelService.saveChannel(adChannel);
    }

    @RequestMapping("/update")
    public ResponseResult updateChannel(@RequestBody AdChannel adChannel) {
        log.info("[data]:{}", adChannel);
        return adChannelService.updateChannel(adChannel);
    }

    @RequestMapping("/del/{id}")
    public ResponseResult deleteChannel(@PathVariable Integer id) {
        log.info("[data]:{}", id);
        return adChannelService.deleteChannelById(id);
    }

    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }
}
